<template>
    <div>
         <el-form-item label="省份" prop="orderNumber">
          <el-select filterable v-model="provinceId" placeholder="请选择省份" v-on:change="getCity(false)">
            <el-option label="请选择省份" value=""> </el-option>
            <el-option v-for="(item,index) in provinceData" :key="index" :label="item.name" :value="item.nid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="市级" prop="orderNumber">
          <el-select v-model.number="cityId" placeholder="请选择市级" v-on:change="getcounty(false)">
            <el-option label="请选择市级" value=""> </el-option>
            <el-option v-for="item in cityData" :key="item.index" :label="item.name" :value="item.nid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="县级" prop="orderNumber">
          <el-select v-model.number="countyId" placeholder="请选择县级" v-on:change="emitId()">
            <el-option label="请选择区级" value=""> </el-option>
            <el-option v-for="item in countyData" :key="item.index" :label="item.name" :value="item.nid">
            </el-option>
          </el-select>
        </el-form-item>
    </div>
</template>

<script>
import agentHttp from '@/utils/agentHttp.js';
export default {
    data(){
        return {
           provinceData:[],   //省数据
           cityData:[],       //市数据
           countyData:[],     //县数据
           code:1,      //省市区顺序 ;
        }
    },
    methods:{
      getProvince(){    //获取省
      // 3 1006 10088
             
		    	    agentHttp.get('adminApi/admin/dictionary/get_province_list').then((data)=>{
			            if(data.success){  
                   this.provinceId?this.provinceId:this.provinceId = data.data[0].nid;
                    this.provinceData = data.data ;

                        this.getCity(true);
			            } 
			        }) 

				 
      }, 
        getCity(code){   //获取市 
            agentHttp.get(`adminApi/admin/dictionary/find_city_new/${this.provinceId}`).then((data)=>{
			            if(data.success){  
                     this.cityId? this.cityId:this.cityId = data.data[0].nid
                     this.cityData = data.data ;
                      this.getcounty(code);
                    if(!code){
                      console.dir(11)
                    }
			            } 
			        }) 
	    	
		  	  
        }, 
      getcounty(code){   //获取县
           
		    	    agentHttp.get('adminApi/admin/dictionary/find_county_new/'+this.cityId).then((data)=>{
			            if(data.success){  
                     this.countyId? this.countyId: this.countyId = data.data[0].nid
                      this.countyData = data.data;
                    
			            } 
			        }) 
      },
      emitId(){
                    const id = {provinceId:this.provinceId,cityId:this.cityId,countyId:this.countyId}
                    // console.dir(id)
                    this.$emit("changeId", id) ;
      }
    },
    props:[ "provinceId","cityId","countyId"],
    created(){
        this.provinceId = this.provinceId||""
        this.cityId = this.cityId||""
        this.countyId = this.countyId||""
        this.getProvince();
    }
}
</script>
